
import time
# 模拟人操作浏览器
from selenium import webdriver
from selenium.webdriver import ActionChains

# 打开浏览器
driver = webdriver.Chrome()  # 创建浏览器对象
# 2.输入访问地址（URL）
url = r"C:\Users\HP\Desktop\UI自动化测试\drop.html"
driver.get(url)
# 放大浏览器页面
# driver.maximize_window()

# 实例化并获取ActionChains类
action = ActionChains(driver)

# 获取 源元素
source = driver.find_element_by_css_selector("#div1")
# 获取 目标元素
target = driver.find_element_by_css_selector("#div2")
time.sleep(3)
action.drag_and_drop(source, target).perform()
# 扩展 通过坐标偏移量执行
time.sleep(3)
action.drag_and_drop_by_offset(source,xoffset=300,yoffset=300).perform()